/*
 * Rubik's JTimer - Copyright (C) 2008 Doug Li
 * JNetCube - Copyright (C) 2007 Chris Hunt
 * Copyright (C) 2008 Ewan Davies
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */
package rubiksjtimer;

public class ScramblePyraminx extends Scramble
{
    private static final String[]   U = {"U", "U'"},
								    L = {"L", "L'"},
								    R = {"R", "R'"},
								    B = {"B", "B'"};
    private static final int NUM_MOVES = 25;
	private int previousArray,currentArray,currentFace;
	private String formatedMove;

	public ScramblePyraminx()
	{
		super();
	}
	
	public String getName() 
	{
		return "Pyraminx";
	}

	private void generateCoreMove()
	{
		currentArray = (int) (Math.abs(generator.nextInt()) % 4);
		currentFace = (int) (Math.abs(generator.nextInt()) % 2);

		String[] arrayChoice = null;
		switch (currentArray)
		{
			case 0: arrayChoice = U;	break;
			case 1: arrayChoice = L;	break;
			case 2: arrayChoice = R;	break;
			case 3: arrayChoice = B;	break;
		}

		formatedMove = arrayChoice[currentFace];		
	}

	public String generateScramble()
	{
		StringBuffer buf = new StringBuffer(3 * NUM_MOVES);
		
		//generate new move
		generateCoreMove();

		//add first move to scramble
		buf.append(formatedMove);
		
		//store current move so that we can generate a new one
		previousArray = currentArray;
		
		//we have one move of the scramble. Now we need to generate the rest.
		for (int i = 0; i < (NUM_MOVES - 1); i++)
		{
			//generate new move
			generateCoreMove();

			//while this move is the same face, or parallel, generate a new one
			while(previousArray == currentArray)
			{
				generateCoreMove();
			}
		
			//add second move to scramble
			buf.append(" ");
			buf.append(formatedMove);

			//store previous and current move so that we can generate a new one
			previousArray = currentArray;		
		}

		int tipChoice = (int) (Math.abs(generator.nextInt()) % 3);

		switch (tipChoice)
		{
			case 0: buf.append(" "); 	buf.append("u");	break;
			case 1: buf.append(" ");	buf.append("u'");	break;
			case 2: break;
		}

		tipChoice = (int) (Math.abs(generator.nextInt()) % 3);

		switch (tipChoice)
		{
			case 0: buf.append(" ");	buf.append("l");	break;
			case 1: buf.append(" ");	buf.append("l'");	break;
			case 2: break;
		}

		tipChoice = (int) (Math.abs(generator.nextInt()) % 3);

		switch (tipChoice)
		{
			case 0: buf.append(" ");	buf.append("r");	break;
			case 1: buf.append(" ");	buf.append("r'");	break;
			case 2: break;
		}

		tipChoice = (int) (Math.abs(generator.nextInt()) % 3);

		switch (tipChoice)
		{
			case 0: buf.append(" ");	buf.append("b");	break;
			case 1: buf.append(" ");	buf.append("b'");	break;
			case 2: break;
		}
		return buf.toString();
	} // end Generate Scramble		
} // end ScramblePyraminx